package com.example.zengyan.myphonebook;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.Gson;

import com.google.gson.reflect.TypeToken;
import com.nightonke.boommenu.BoomMenuButton;
import com.nightonke.boommenu.Types.BoomType;
import com.nightonke.boommenu.Types.ButtonType;
import com.nightonke.boommenu.Types.PlaceType;
import com.nightonke.boommenu.Util;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;
import com.zhy.http.okhttp.https.HttpsUtils;

import org.litepal.crud.DataSupport;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import BD.HttpUtil;
import BD.SQLiteUtil;
import Bean.Member;
import Bean.Organization;
import fragments.ItemFragment;
import android.support.v7.widget.LinearLayoutManager;

import static BD.mConfig.*;

public class MainActivity extends AppCompatActivity implements BoomMenuButton.OnSubButtonClickListener{
    private String answerString;
    private TextView answer;
    private RecyclerView mRecyclerView;
    private BaseQuickAdapter<Organization> mQuickAdapter;

    private BoomMenuButton boomMenuButton;

    private int[] BtnDrawables={
            R.mipmap.leave,
            R.mipmap.flash,
            R.mipmap.mine

    };
    private Drawable[] subButtonDrawables=new Drawable[3];
    String[] subButtonTexts = new String[]{
            "离开",
            "刷新",
            "我的",

    };
    int[][] subButtonColors = new int[3][2];


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mRecyclerView = (RecyclerView) findViewById(R.id.list);

        final ArrayList<Organization> allO= (ArrayList<Organization>) DataSupport.findAll(Organization.class,true);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
        mRecyclerView.setAdapter(mQuickAdapter=new BaseQuickAdapter<Organization>(MainActivity.this,R.layout.mainlistview_layout,allO) {
            @Override
            protected void convert(BaseViewHolder baseViewHolder, Organization organization) {
                baseViewHolder.setText(R.id.info_text,organization.getOname());
            }
        });

        mQuickAdapter.setOnRecyclerViewItemClickListener(new BaseQuickAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int i) {
                Log.d(TAG, "onItemClick: "+allO.size()+"!!!!");
                FragmentActivity.startActivity(MainActivity.this, allO.get(i).getOid());
               ArrayList<Organization> allo= (ArrayList<Organization>) DataSupport.findAll(Organization.class);
                for (Organization o:allo
                     ) {
                    Log.d(TAG, "onItemClick: "+o.getOid());

                }
            }
        });







//        for (int i = 0; i < 3; i++) {
//            Log.d(TAG, "drawable" + i);
//            subButtonDrawables[i] = ContextCompat.getDrawable(this, BtnDrawables[i]);
//        }
        for (int i = 0; i < 3; i++) {
            Log.d(TAG, "color" + i);
            subButtonColors[i][1] = ContextCompat.getColor(this, R.color.primary);
            subButtonColors[i][0] = Util.getInstance().getPressedColor(subButtonColors[i][1]);
        }
        boomMenuButton = (BoomMenuButton) findViewById(R.id.boom);
        boomMenuButton.setOnSubButtonClickListener(this);

    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {

        boomMenuButton.init(
                subButtonDrawables, // 子按钮的图标Drawable数组，不可以为null
                subButtonTexts,     // 子按钮的文本String数组，可以为null
                subButtonColors,    // 子按钮的背景颜色color二维数组，包括按下和正常状态的颜色，不可为null
                ButtonType.CIRCLE,     // 子按钮的类型
                BoomType.HORIZONTAL_THROW,  // 爆炸类型
                PlaceType.CIRCLE_3_1,  // 排列类型
                null,               // 展开时子按钮移动的缓动函数类型
                null,               // 展开时子按钮放大的缓动函数类型
                null,               // 展开时子按钮旋转的缓动函数类型
                null,               // 隐藏时子按钮移动的缓动函数类型
                null,               // 隐藏时子按钮缩小的缓动函数类型
                null,               // 隐藏时子按钮旋转的缓动函数类型
                null                // 旋转角度
        );
    }


    @Override
    public void onClick(int buttonIndex) {
        switch (buttonIndex) {
            case 0:
                this.finish();
                Intent n=new Intent(MainActivity.this,LoginActivity.class);
                n.putExtra("leave",true);
                startActivity(n);

                break;

            case 1:
                break;

            case 2:
                break;

        }
    }


}
